finding nth term for linear sequences